package com.jp.vn.main;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.jp.vn.CustomAdapter.SoDemAdapter;
import com.jp.vn.Object.Category;
import com.jp.vn.Object.SoDem;

public class SoDemActivity extends Activity {

	ArrayList<Category> arrayCategoryNum = new ArrayList<Category>();
	LinearLayout menu_popup;
	ImageView btnMenu;
	int height = 0;
	int width = 0;
	int space = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_so_dem);
		
		menu_popup = (LinearLayout)findViewById(R.id.menu_popup);
		btnMenu = (ImageView) findViewById(R.id.btnMenu);

		dumyData();

		ExpandableListView listView = (ExpandableListView) findViewById(R.id.listNum);

		listView.setGroupIndicator(null);

		SoDemAdapter adapter = new SoDemAdapter(getApplicationContext(),
				arrayCategoryNum);

		listView.setAdapter(adapter);
		
		btnMenu.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				PopupMenu menu =  new PopupMenu(v, height, width);
				menu.showPopup(space+5);
			}
		});

	}
	
	@Override
	protected void onPause() {
		super.onPause();
		finish();
	}
	
	@Override
	public void onBackPressed() {
		super.onBackPressed();
		overridePendingTransition(R.anim.left_in, R.anim.right_out);
		finish();
	}
	
	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		super.onWindowFocusChanged(hasFocus);
		width = menu_popup.getWidth();
		menu_popup.setVisibility(View.GONE);
		height = (int) getResources().getDimension(R.dimen.menupopup_height);
		space = (int) getResources().getDimension(R.dimen.menu_height);
	}

	void dumyData() {

		Category category1 = new Category();
		category1.setName("Số đếm từ 0 -> 10");
		ArrayList<SoDem> arrayNum1 = new ArrayList<SoDem>();
		arrayNum1.add(new SoDem("0", "ゼロ, れい", "zero, rei"));
		arrayNum1.add(new SoDem("1", "いち", "i chi"));
		arrayNum1.add(new SoDem("2", "に", "ni"));
		arrayNum1.add(new SoDem("3", "さん", "san"));
		arrayNum1.add(new SoDem("4", "よん, し", "yon, shi"));
		arrayNum1.add(new SoDem("5", "ご", "go"));
		arrayNum1.add(new SoDem("6", "ろく", "roku"));
		arrayNum1.add(new SoDem("7", "なな, しち", "nana, shichi"));
		arrayNum1.add(new SoDem("8", "はち", "hachi"));
		arrayNum1.add(new SoDem("9", "きゅう, く", "kyuu, ku"));
		arrayNum1.add(new SoDem("10","じゅう", "juu"));
		category1.setArraySoDem(arrayNum1);
		arrayCategoryNum.add(category1);

		Category category2 = new Category();
		category2.setName("Số đếm hàng chục");
		ArrayList<SoDem> arrayNum2 = new ArrayList<SoDem>();
		arrayNum2.add(new SoDem("11", "じゅういち", "juu ichi"));
		arrayNum2.add(new SoDem("12", "じゅうに", "juu ni"));
		arrayNum2.add(new SoDem("13", "じゅうさん", "juu san"));
		arrayNum2.add(new SoDem("14", "じゅうよん", "juu yon"));
		arrayNum2.add(new SoDem("15", "じゅうご", "juu go"));
		arrayNum2.add(new SoDem("16", "じゅうろく", "juu roku"));
		arrayNum2.add(new SoDem("17", "じゅうなな", "juu nana"));
		arrayNum2.add(new SoDem("18", "じゅうはち", "juu hachi"));
		arrayNum2.add(new SoDem("19", "じゅうきゅう", "juu kyuu"));
		arrayNum2.add(new SoDem("20", "にじゅう", "ni juu"));
		arrayNum2.add(new SoDem("30", "さんじゅう", "san juu"));
		arrayNum2.add(new SoDem("40", "よんじゅう", "yon juu"));
		arrayNum2.add(new SoDem("50", "ごじゅう", "go juu"));
		arrayNum2.add(new SoDem("60", "ろくじゅう", "roku juu"));
		arrayNum2.add(new SoDem("70", "ななじゅう", "nana juu"));
		arrayNum2.add(new SoDem("80", "はちじゅう", "hachi juu"));
		arrayNum2.add(new SoDem("90", "きゅうじゅう", "kyuu juu"));
		category2.setArraySoDem(arrayNum2);
		arrayCategoryNum.add(category2);

		Category category3 = new Category();
		category3.setName("Số đếm hàng trăm");
		ArrayList<SoDem> arrayNum3 = new ArrayList<SoDem>();
		arrayNum3.add(new SoDem("100", "ひゃく", "hyaku"));
		arrayNum3.add(new SoDem("200", "にひゃく", "ni hyaku"));
		arrayNum3.add(new SoDem("300", "さんびゃく", "san byaku"));
		arrayNum3.add(new SoDem("400", "よんひゃく", "yon hyaku"));
		arrayNum3.add(new SoDem("500", "ごひゃく", "go hyaku"));
		arrayNum3.add(new SoDem("600", "ろっぴゃく", "roppyaku"));
		arrayNum3.add(new SoDem("700", "ななひゃく", "nana hyaku"));
		arrayNum3.add(new SoDem("800", "はっぴゃく", "happyaku"));
		arrayNum3.add(new SoDem("900", "きゅうひゃく", "kyuu hyaku"));
		category3.setArraySoDem(arrayNum3);
		arrayCategoryNum.add(category3);

		Category category4 = new Category();
		category4.setName("Số đếm hàng nghìn");
		ArrayList<SoDem> arrayNum4 = new ArrayList<SoDem>();
		arrayNum4.add(new SoDem("1000", "せん", "sen"));
		arrayNum4.add(new SoDem("2000", "にせん", "ni sen"));
		arrayNum4.add(new SoDem("3000", "さんぜん", "san zen"));
		arrayNum4.add(new SoDem("4000", "よんせん", "yon sen"));
		arrayNum4.add(new SoDem("5000", "ごせん", "go sen"));
		arrayNum4.add(new SoDem("6000", "ろくせん", "roku sen"));
		arrayNum4.add(new SoDem("7000", "ななせん", "nana sen"));
		arrayNum4.add(new SoDem("8000", "はっせん", "hassen"));
		arrayNum4.add(new SoDem("9000", "きゅうせん", "kyuu sen"));
		category4.setArraySoDem(arrayNum4);
		arrayCategoryNum.add(category4);

		Category category5 = new Category();
		category5.setName("Số đếm hàng vạn");
		ArrayList<SoDem> arrayNum5 = new ArrayList<SoDem>();
		arrayNum5.add(new SoDem("10000","いちまん", "ichi man"));
		arrayNum5.add(new SoDem("100000","じゅうまん", "juu man"));
		arrayNum5.add(new SoDem("1000000","ひゃくまん", "hyaku man"));
		arrayNum5.add(new SoDem("10000000","せんまん", "sen man"));
		category5.setArraySoDem(arrayNum5);
		arrayCategoryNum.add(category5);

		Category category6 = new Category();
		category6.setName("Một số ví dụ khác");
		ArrayList<SoDem> arrayNum6 = new ArrayList<SoDem>();
		arrayNum6.add(new SoDem("37","さんじゅうなな",""));
		arrayNum6.add(new SoDem("145","ひゃくよんじゅうご",""));
		arrayNum6.add(new SoDem("1378","せんさんびゃくななじゅうはち",""));
		arrayNum6.add(new SoDem("47600","よんまんななせんろっぴゃく",""));
		arrayNum6.add(new SoDem("278000","にじゅうななまんはっせん",""));
		category6.setArraySoDem(arrayNum6);
		arrayCategoryNum.add(category6);
	}
}
